<template>
    <div>
      <h3>{{msg}}</h3>
      <from>
        账号:<input v-model="admin.username" type="text"><br/>
        密码:<input v-model="admin.password" type="text"><br/>
        <input type="button" value="登录" @click="login">
        <input type="button" value="重填">
      </from>
      <span style="color: red">{{errMsg}}</span>
    </div>
</template>

<script>
import instance from "../utils/request";

export default {
  name: "login",
  data(){
    return{
      msg:"用户登录",
      admin:{},
      errMsg:""
    }
  },
  methods:{
    login(){
      instance.post("/admin/login",this.admin)
      .then(res=>{
        let result = res.data;
        if (result.login=="ok"){
          // 往浏览器的本地存储中 存储信息 sessonid
          localStorage.setItem("token",result.token);
          this.$router.push({name:"welcome"});
        }else {
          this.errMsg = result.errMsg;
        }
      })
      // 发异步请求，检查 帐号密码
      // axios.post("url", this.admin).then(res=>);
      // 到主页显示
      this.$router.push({name:"welcome"});
    }
  }
}
</script>

<style scoped>

</style>
